using Microsoft.AspNetCore.Mvc.Filters;

using System.Linq;
using System.Security.Claims;

using Tool;

namespace Abc.Web.Core
{
    public class FilterContextInfo
    {
        public FilterContextInfo(ActionExecutingContext filterContext)
        {
            #region 获取链接中的字符
            //try
            //{
            //    if (filterContext.HttpContext.User.Claims.Any(o => o.Type == ClaimTypes.Sid))
            //    {
            //        var sid = filterContext.HttpContext.User.FindFirst(ClaimTypes.Sid).Value;
            //        this.UserId = sid.To<int>();
            //    }
            //}
            //catch (System.Exception ex)
            //{
            //}

            this.UserId = filterContext.HttpContext.GetLoginUserId<int>();

            // 获取域名
            DomainName = filterContext.HttpContext.Request.Host.Value;

            //获取模块名称
            //  module = filterContext.HttpContext.Request.Url.Segments[1].Replace('/', ' ').Trim();

            //area
            Area = filterContext.RouteData.Values["area"].ToString();

            //获取 controllerName 名称
            ControllerName = filterContext.RouteData.Values["controller"].ToString();

            //获取ACTION 名称
            ActionName = filterContext.RouteData.Values["action"].ToString();

            #endregion 获取链接中的字符
        }

        public int UserId { get; set; }

        /// <summary>
        /// 获取域名
        /// </summary>
        public string DomainName { get; set; }

        /// <summary>
        /// 获取模块名称
        /// </summary>
        public string Area { get; set; }

        /// <summary>
        /// 获取 controllerName 名称
        /// </summary>
        public string ControllerName { get; set; }

        /// <summary>
        /// 获取ACTION 名称
        /// </summary>
        public string ActionName { get; set; }
    }
}